local funan = fk.CreateSkill{
  name = "hanqing__funan",
  dynamic_desc = function (self, player, lang)
    if player:getMark(self.name) > 0 then
      return "hanqing__funan_inner"
    end
  end,
}

Fk:loadTranslationTable{
  ["hanqing__funan"] = "覆南",
  [":hanqing__funan"] = "你可以将中央区任意张【杀】置于牌堆顶，视为使用【无懈可击】；若以此法选择牌数不大于上一次，"..
  "交换描述中的【杀】和【无懈可击】。",

  [":hanqing__funan_inner"] = "你可以将中央区任意张【无懈可击】置于牌堆顶，视为使用【杀】；若以此法选择牌数不大于上一次，"..
  "交换描述中的【杀】和【无懈可击】。",

  ["#hanqing__funan"] = "覆南：你可以将中央区的【%arg】置于牌堆顶，视为使用【%arg2】",
}

funan:addEffect("viewas", {
  anim_type = "offensive",
  pattern = "slash,nullification",
  expand_pile = function (self)
    return Fk:currentRoom():getBanner("@$CenterArea")
  end,
  prompt = function (self, player)
    local name1, name2 = "slash", "nullification"
    if player:getMark(funan.name) > 0 then
      name1, name2 = "nullification", "slash"
    end
    return "#hanqing__funan:::"..name1..":"..name2
  end,
  card_filter = function(self, player, to_select, selected)
    if table.contains(Fk:currentRoom():getBanner("@$CenterArea"), to_select) then
      if player:getMark(funan.name) == 0 then
        return Fk:getCardById(to_select).trueName == "slash"
      else
        return Fk:getCardById(to_select).trueName == "nullification"
      end
    end
  end,
  view_as = function(self, player, cards)
    if #cards == 0 then return end
    local name = player:getMark(funan.name) == 0 and "nullification" or "slash"
    local card = Fk:cloneCard(name)
    card.skillName = funan.name
    card:addFakeSubcards(cards)
    return card
  end,
  before_use = function (self, player, use)
    local room = player.room
    local cards = use.card.fake_subcards
    if #cards <= player:getMark("hanqing__funan_count") then
      room:setPlayerMark(player, funan.name, player:getMark(funan.name) == 0 and 1 or 0)
    end
    room:setPlayerMark(player, "hanqing__funan_count", #cards)
    room:moveCards({
      ids = cards,
      fromArea = Card.DiscardPile,
      toArea = Card.DrawPile,
      moveReason = fk.ReasonPut,
      skillName = funan.name,
      moveVisible = true,
      drawPilePosition = 1,
    })
  end,
  enabled_at_play = function (self, player)
    return player:getMark(funan.name) > 0
  end,
  enabled_at_response = function(self, player, response)
    if response or #Fk:currentRoom():getBanner("@$CenterArea") == 0 then return end
    local name1, name2 = "slash", "nullification"
    if player:getMark(funan.name) == 1 then
      name1, name2 = "nullification", "slash"
    end
    if not table.find(Fk:currentRoom():getBanner("@$CenterArea"), function (id)
      return Fk:getCardById(id).trueName == name1
    end) then return end
    return #player:getViewAsCardNames(funan.name, {name2}) > 0
  end,
  enabled_at_nullification = function (self, player, data)
    return player:getMark(funan.name) == 0 and
      table.find(Fk:currentRoom():getBanner("@$CenterArea"), function (id)
        return Fk:getCardById(id).trueName == "slash"
      end)
  end,
})

funan:addAcquireEffect(function (self, player, is_start)
  player.room:addSkill("#CenterArea")
end)

funan:addAI(nil, "vs_skill")

return funan
